home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Hot Mix 17
/
Hot Mix 17.iso
/
HM17_SGI
/
research
/
examples
/
demo
/
demosrc
/
demo.pro
< prev
next >
Wrap
Text File
|
1997-07-08
|
41KB
|
1,256 lines
;$Id: demo.pro,v 1.65 1997/04/28 21:10:45 alan Exp $
;
; Copyright (c) 1997, Research Systems, Inc. All rights reserved.
; Unauthorized reproduction prohibited.
;
;+
; FILE:
; demo.pro
;
; CALLING SEQUENCE: demo
;
; PURPOSE:
; Main demo shell.
;
; MAJOR TOPICS: All topics in IDL 5.0.
;
; CATEGORY:
; IDL 5.0
;
; INTERNAL FUNCTIONS and PROCEDURES:
;
; EXTERNAL FUNCTIONS, PROCEDURES, and FILES:
; pro gettips - Read the tip file
; pro widtips - Create the tip widgets
; pro sizetips - Size the tip widgets
;
; REFERENCE: IDL Reference Guide, IDL User's Guide
;
; NAMED STRUCTURES:
; none.
;
; COMMON BLOCS:
; none.
;
; MODIFICATION HISTORY:
; 3/97, ACY - Modified
;-
;----------------------------------------------------------------------------
;
; Purpose: Display a message.
;
function temp_msg, $
string ; IN: message string
message = ["Not yet implemented..."," ", $
"When implemented, will go to", " " + string]
temp = DIALOG_MESSAGE ( message )
end
pro timer, text, t0 ;Print times & update current time
t1 = systime(1)
print, text, ' ', t1 - t0
t0 = t1
end
pro DoAScreen, Index, lun, hdr, Image, R, G, B
; Writes an image to the gif file, and saves its color table in the
; header structure. We assume that images may have a maximum of 128
; colors.
m = max(image)
if m gt 127 then begin
print, 'Image ', index,' is out of range, reducing'
reduce_colors, Image, v
if n_elements(v) lt 128 then v = [v, bytarr(128 - n_elements(v))]
r = r(v)
g = g(v)
b = b(v)
endif
point_lun, -lun, position ;Get & save current position
hdr[index].start = position
hdr[index].dims = (size(image))(1:2)
for j=0, (n_elements(r) < 128)-1 do begin
hdr[index].colortb[j] = r[j]
hdr[index].colortb[j+128] = g[j]
hdr[index].colortb[j+256] = b[j]
endfor
ENCODE_GIF, lun, Image
print, index, position, m
end
;----------------------------------------------------------------------------
;
; Purpose: Create the gif file from the .sav file
;
pro WriteDemoscreen
t0 = systime(1)
restore, filepath('screens.sav', SUBDIR=['examples','demo','demodata'])
timer, 'ReadImages/restore', t0
lun = 0
nimages = long(15)
openw, lun, 'screens.gif', /get_lun
header = replicate({ Start: 0L, dims: lonarr(2), $
colortb: bytarr(128*3)}, nimages)
writeu, lun, nimages, header
DoAScreen, 0, lun, header, mainScreen, MainR, MainG, MainB
DoAScreen, 1, lun, header, analysisScreen, analysisR, analysisG, analysisB
DoAScreen, 2, lun, header, appdevScreen, appdevR,appdevG,appdevB
DoAScreen, 3, lun, header, callrsiScreen, callrsiR,callrsiG,callrsiB
DoAScreen, 4, lun, header, earthScreen, earthR,earthG,earthB
DoAScreen, 5, lun, header, engineerScreen, engineerR,engineerG,engineerB
DoAScreen, 6, lun, header, medicalScreen, medicalR,medicalG,medicalB
DoAScreen, 7, lun, header, rsiprodScreen, rsiprodR,rsiprodG,rsiprodB
DoAScreen, 8, lun, header, spaceScreen, spaceR,spaceG,spaceB
DoAScreen, 9, lun, header, vizScreen, vizR,vizG,vizB
DoAScreen, 10, lun, header, enviScreen,enviR,enviG,enviB
DoAScreen, 11, lun, header, vhScreen,vhR,vhG,vhB
DoAScreen, 12, lun, header, dataminerScreen,dataminerR,dataminerG,dataminerB
DoAScreen, 13, lun, header, insightScreen,insightR,insightG,insightB
; Save the initial splash scren as the last image...
READ_GIF, filepath("splash.gif", $
SUBDIR=['examples','demo','demodata']), $
splashImg, splashR, splashG, splashB
DoAScreen, 14, lun, header, splashImg, splashR, splashG, splashB
point_lun, lun, 0
byteorder, nimages, /HTONL
tmp = header.start
byteorder, tmp, /HTONL
header.start = tmp
writeu, lun, nimages, header
free_lun, lun
end
Function OpenDemoscreens, Name, Header
; Open the Demo screens file and read the header, If OK return 1,
; otherwise negative error code.
openr, lun, name, /GET_LUN, ERROR=i ;Open up the file containing screens
if i lt 0 then begin
j = DIALOG_MESSAGE(["Can't read the demo screen file", Name], /ERROR)
return, i
endif
nimages = 0L
readu, lun, nimages ;Read # of images
byteorder, nimages, /NTOHL ;Correct byteorder
tmp = replicate({ Start: 0L, $ ;Read file header
dims: lonarr(2), $
colortb: bytarr(128,3)$
}, nimages)
readu, lun, tmp
t = tmp.start ;Correct for byte ordering
byteorder, t, /NTOHL
tmp.start = t
t = tmp.dims
byteorder, t, /NTOHL
tmp.dims = t
header = { lun : lun, $ ;Combine
count: 0L, $
start: tmp.start, $
dims: tmp.dims, $
colortb: tmp.colortb, $
cache: ptrarr(nimages), $
time: lonarr(nimages)}
return, 1
end
Function PReadDemoScreen, Index, Header, Colortable, NO_CACHE=no_cache, $
DEBUG = debug
; Return a pointer to an image for screen number Index.
; Return colortable in Colortable
;
Null = ptr_new()
Nkeep = 3 ;# of images to keep in cache
Header.count = Header.count + 1 ;Keep track of time
if Header.cache(Index) ne Null then begin ;Already there?
Result = Header.cache(Index)
; if keyword_set(debug) then print,'cached ', Index
endif else begin
in = where(header.cache ne Null, count)
if count ge Nkeep then begin ;Must get rid of an image
junk = min(header.time(in), Toss);Find image that been in the longest
toss = in(toss)
; if keyword_set(debug) then print, 'Removed ', toss
ptr_free, Header.cache(toss)
Header.cache(toss) = Null
endif
lun = Header.Lun
point_lun, lun, Header.start[index] ;Start of image in file
image = bytarr(Header.dims[0,index], Header.dims[1,index], $ ;Array to Read
/NOZERO)
DECODE_GIF, lun, Image
result = ptr_new(Image, /NO_COPY)
if keyword_set(no_cache) eq 0 then Header.cache(Index) = result
; if keyword_set(debug) then print, 'Read ', index
endelse
Header.time[Index] = Header.count
Colortable = Reform(Header.colortb(*,*,Index))
Return, Result ;Return the pointer to the image
end
;----------------------------------------------------------------------------
;
; Purpose: Set up the splash screens.
;
pro demoSplashStart, $
fullScrXsize, $ ; IN: X monitor size
fullScrYsize, $ ; IN: Y monitor size
splashImage, $ ; IN: Image to display
splashColors, $ ; IN: Colortable for image
splashBase, $ ; OUT: Splash base ID
startSplash ; OUT: Starting time
s = size(splashImage)
nx = s(1)
ny = s(2)
splashXoffset = (fullScrXsize-nx)/2
splashYoffset = (fullScrYsize-ny)/2
splashBase = WIDGET_BASE ( tlb_frame_attr=31, $
xoffset=splashXoffset, yoffset=splashYoffset )
splashDraw = widget_draw ( splashBase, xsize=nx, ysize=ny )
WIDGET_CONTROL, splashBase, map=0
WIDGET_CONTROL, splashBase, /realize
TVLCT, SplashColors
WIDGET_CONTROL, splashDraw, GET_VALUE=splashDrawID
WSET, splashDrawID
TV, splashImage
splashImage = 0 ;Don't need it anymore
WIDGET_CONTROL, splashBase, map=1
startSplash = systime ( 1 )
end
;----------------------------------------------------------------------------
;
; Purpose: End the display of the splash screen
;
pro demoSplashEnd, $
startSplash, $ ; IN: Starting time
splashBase, $ ; IN: Splash base ID
debug ; IN: Debug mode 1=on, 0= off
; End the display of the splash screen
;
endSplash = systime ( 1 )
deltaSplash = endSplash - startSplash
if ( debug eq 1 ) then begin
print, " Elapsed time for splash screen =====", deltaSplash
end
; while ( deltaSplash le 4.0 ) do begin
; print, 'In wait loop ...'
; wait, 0.25
; deltaSplash = systime ( 1 ) - endSplash
; endwhile
WIDGET_CONTROL, splashBase, /destroy
;if ( debug eq 1 ) then begin
;print, " Total elapsed time for splash screen ", deltaSplash
;end
end
;----------------------------------------------------------------------------
;
; Purpose: Reset the system variables.
;
pro idl_demo_reset
Set_Shading, LIGHT=[0.0, 0.0, 1.0], /REJECT, /GOURAUD, $
VALUES=[0, (!D.N_Colors-1L)]
T3d, /RESET
!P.T3d = 0
!P.Position = [0.0, 0.0, 0.0, 0.0]
!P.Clip = [0L, 0L, (!D.X_Size-1L), (!D.Y_Size-1L), 0L, 0L]
!P.Region = [0.0, 0.0, 0.0, 0.0]
!P.Background = 0L
!P.Charsize = 8.0 / Float(!D.X_Ch_Size)
!P.Charthick = 0.0
!P.Color = !D.N_Colors - 1L
!P.Font = (-1L)
!P.Linestyle = 0L
!P.Multi = [0L, 0L, 0L, 0L, 0L]
!P.Noclip = 0L
!P.Noerase = 0L
!P.Nsum = 0L
!P.Psym = 0L
!P.Subtitle = ''
!P.Symsize = 0.0
!P.Thick = 0.0
!P.Title = ''
!P.Ticklen = 0.02
!P.Channel = 0
!X.S = [0.0, 1.0]
!X.Style = 0L
!X.Range = 0
!X.Type = 0L
!X.Ticks = 0L
!X.Ticklen = 0.0
!X.Thick = 0.0
!X.Crange = 0.0
!X.Omargin = 0.0
!X.Window = 0.0
!X.Region = 0.0
!X.Charsize = 0.0
!X.Minor = 0L
!X.Tickv = 0.0
!X.Tickname = ''
!X.Gridstyle = 0L
!X.Tickformat = ''
!Y = !X
!Z = !X
!X.Margin = [10.0, 3.0] ;.Margin is different for x,y,z
!Y.Margin = [4.0, 2.0]
!Z.Margin = 0
end
pro button_group, buttons, index, x0, y0, ydelta, screen, Names, DEFINE=ndefine
; Define a column of buttons.
; Inputs: buttons = array of button structures.
; Index = index of next button to define. On exit, index is incremented.
; x0, y0 = starting coordinate for the first button. y0 is output as
; the starting coordinate for the next button.
; ydelta = vertical spacing between buttons.
; screen = screen index of button.
; Names = [2,n] array of Button values and uvalues.
n = n_elements(names)/2
xsize = 130
ysize = 23
for i=0, n-1 do begin
s = { d5btn_s, $
Value: Names[i*2], $
Uvalue: Names[i*2+1], $
xsize: xsize, $
ysize: ysize, $
xoffset: fix(x0), $
yoffset: fix(y0), $
screenNum: fix(screen), $
btnbase: 0L$
}
if index eq 0 then $ ;Define array?
buttons = replicate(s, ndefine)
buttons[index] = s
y0 = y0 + ydelta
index = index + 1
endfor
end
;----------------------------------------------------------------------------
;
; Purpose: Define (not create) the push down
; buttons within the splash screens.
;
pro buttonDef, buttons
numButtons = 71
index = 0
; Main level buttons, screen 0, group 1
ystart = 115
button_group, buttons, index, 36, ystart, 27, 0, DEFINE=numButtons, $
['Earth Sciences', '.4', $ ; Main level buttons, screen 0, group 1
'Engineering', '.5', $
'Medical', '.6', $
'Space/Physics', '.8']
button_group, buttons, index, 36, ystart + 27, 27, 0, $
['RSI Products', '.7']
; Main level buttons, screen 0, group 2
ystart = 243
button_group, buttons, index, 485, ystart, 27, 0, $
['Visualization', '.9', $
'Data Analysis', '.1', $
'Application Development', '.2']
button_group, buttons, index, 485, ystart + 27, 27, 0, $
['Contact RSI', '.3']
; Second Level Buttons, screens are listed in alphabetical order,
; not screen order. Vertical Spacing is 29 pixels.
; Analysis Buttons, screen 1
button_group, buttons, index, 75, 40, 29, 1, $
[ 'Math and Statistics', 'D_MATHSTAT', $
'Matrix Data', 'D_MATRIX', $
'Signal Processing', 'FILTER-SIGNAL', $
'Image Processing', 'D_IMAGPROC', $
'Venn Diagrams', 'D_VENN', $
'Wavelets', 'D_WAVELET', $
'People of RSI', 'D_PEOPLE', $
'Return to Main Screen', '.0']
button_group, buttons, index, 330, 200, 29, 2, $
[ 'GUI Development', 'D_WIDGETS', $ ; AppDev Buttons, screen 2
'Database Connectivity','.12', $
'Development Environment','?DEVENV', $
'OO Programming', '?OOPROG', $
'Cross Platform Dev', '?CROSS', $
'Return to Main Screen', '.0']
button_group, buttons, index, 383, 324, 29, 3, $
[ 'Return to Main Screen', '.0']
button_group, buttons, index, 85, 38, 29, 4, $
['Mapping', 'D_MAP', $ ; Earth Buttons, screen 4
'Tides', 'D_TIDES', $
'Globe', 'D_GLOBE', $
'Texture Mapping', 'D_TEXTURE', $
'Flyby', 'D_FLYBY', $
'Environmental Modeling', 'D_TANKLEAK', $
'ENVI', '.10', $
'Return to Main Screen', '.0']
button_group, buttons, index, 66, 57, 29, 5, $
['Forecasting', 'D_FORECAST', $ ; Engineering Buttons, screen 5
'Optimization', 'D_OPTIMIZE', $
'Fourier Filtering', 'FILTER-ENGR', $
'CFD', 'D_CFD', $
'Time Series', 'D_T_SERIES', $
'Return to Main Screen', '.0']
button_group, buttons, index, 402, 92, 29, 6, $
['Reconstruction', 'D_RECONSTR', $ ; Medical Buttons, screen 6
'Image Animation', 'D_GATED', $
'Beating Heart', 'D_HEART', $
'Volumes', 'D_VOLRENDR', $
'Visible Human', '.11', $
'Return to Main Screen', '.0']
button_group, buttons, index, 410, 100, 29, 7, $
['IDL Insight', '.13', $ ; RSI Product Buttons, screen 7
'ENVI', '.10', $
'Visible Human', '.11', $
'IDL DataMiner', '.12', $
'Return to Main Screen', '.0']
button_group, buttons, index, 29, 261, 29, 8, $
['Fourier Filtering', 'FILTER-SPACE', $ ; Space Buttons, screen 8
'ROI Segmentation', 'ROI-SPACE', $
'Return to Main Screen', '.0']
if !version.os_family NE 'Windows' then begin
button_group, buttons, index, 53, 160, 29, 9, $
['2D Plotting', 'D_PLOT2D', $ ; Viz Buttons, screen 9, group 1
'Contouring', 'D_CONTOUR', $
'3D Geometry', 'D_OBJECT3D', $
'Surface Objects', 'D_SURFVIEW', $
'Volumes', 'D_VOLRENDR', $
'US Census', 'D_USCENSUS', $
'Vibrating Membrane', 'D_VIBMEMBR']
endif else begin
;;; Don't allow US Census demo if Windows
button_group, buttons, index, 53, 160, 29, 9, $
['2D Plotting', 'D_PLOT2D', $ ; Viz Buttons, screen 9, group 1
'Contouring', 'D_CONTOUR', $
'3D Geometry', 'D_OBJECT3D', $
'Surface Objects', 'D_SURFVIEW', $
'Volumes', 'D_VOLRENDR', $
'Vibrating Membrane', 'D_VIBMEMBR']
endelse
button_group, buttons, index, 390, 125, 29, 9, $
['Mapping', 'D_MAP', $ ; Viz Buttons, screen 9, group 2
'Gridding', 'D_GRIDDING', $
'Texture Mapping', 'D_TEXTURE', $
'Flyby', 'D_FLYBY', $
'Orbit', 'D_ORBIT', $
'Slicer', 'D_SLICE', $
'Return to Main Screen', '.0']
button_group, buttons, index, 20, 375, 29, 10, $ ; ENVI Buttons, screen 10
['Back','.-']
button_group, buttons, index, 20, 375, 29, 11, $ ; VH Buttons, screen 11
['Back','.-']
button_group, buttons, index, 20, 375, 29, 12, $ ; DataMiner Buttons, screen 12
['Back','.-']
button_group, buttons, index, 120, 275, 29, 13, $ ; Insight Buttons, screen 13
['Start IDL Insight','INSIGHT-START']
button_group, buttons, index, 20, 375, 29, 13, $
['Back','.-']
end
pro GetMenuDescription, MenuDescription ;Define the menu string arrays.
MenuDescription = $
[ '1\File', '', $
'2\Quit', 'quit', $
'1\Applications', '', $
'1\Earth Sciences', '', $
'0\Mapping', 'D_MAP', $
'0\Oceanic Tides Animation', 'D_TIDES', $
'0\Globe', 'D_GLOBE', $
'0\Texture Mapped Terrain', 'D_TEXTURE', $
'0\Terrain Flyby', 'D_FLYBY', $
'0\Environmental Modeling', 'D_TANKLEAK', $
'2\ENVI', '.10', $
'1\Engineering', '', $
'0\Forecasting', 'D_FORECAST', $
'0\Optimization', 'D_OPTIMIZE', $
'0\Fourier Filtering', 'FILTER-ENGR', $
'0\Computational Fluid Dynamics', 'D_CFD', $
'2\Time Series', 'D_T_SERIES', $
'1\Medical', '', $
'0\Image Reconstruction', 'D_RECONSTR', $
'0\Image Animation', 'D_GATED', $
'0\Beating Heart', 'D_HEART', $
'0\Volume Visualization', 'D_VOLRENDR', $
'2\Visible Human', '.11' ]
if !version.os_family NE 'Windows' then begin
MenuDescription = $ ;Cause strings are too long to concatenate
[ MenuDescription, $
'1\Physics and Space Sciences', '', $
'0\Fourier Filtering', 'FILTER-SPACE', $
'2\ROI Segmentation', 'ROI-SPACE', $
'3\RSI Products', '', $
'0\IDL Insight', '.13', $
'0\ENVI', '.10', $
'0\Visible Human CD', '.11', $
'2\IDL Dataminer', '.12', $
'1\Features', '', $
'1\Visualization', '', $
'0\2D Plotting', 'D_PLOT2D', $
'0\Contouring', 'D_CONTOUR', $
'0\3D Geometry Viewing', 'D_OBJECT3D', $
'0\Surface Objects', 'D_SURFVIEW', $
'0\Volume Visualization', 'D_VOLRENDR', $
'0\US Census', 'D_USCENSUS', $
'0\Vibrating Membrane', 'D_VIBMEMBR', $
'0\Mapping', 'D_MAP', $
'0\Gridding and Interpolation', 'D_GRIDDING', $
'0\Texture Mapped Terrain', 'D_TEXTURE', $
'0\Terrain Flyby', 'D_FLYBY', $
'0\Orbiting Satellite', 'D_ORBIT', $
'2\Slicer', 'D_SLICE', $
'1\Data Analysis', '', $
'0\Math and Statistics', 'D_MATHSTAT', $
'0\Matrix Data', 'D_MATRIX', $
'0\Signal Processing', 'FILTER-SIGNAL', $
'0\Image Processing', 'D_IMAGPROC', $
'0\Venn Diagrams', 'D_VENN', $
'0\Wavelets', 'D_WAVELET', $
'2\The People of RSI', 'D_PEOPLE', $
'3\Application Development', '',$
'0\GUI Development', 'D_WIDGETS', $
'0\Database Connectivity', '.12', $
'0\Development Environment', '?DEVENV', $
'0\Object Oriented Programming', '?OOPROG', $
'2\Cross Platform Development', '?CROSS']
endif else begin
;;; Don't allow US Census demo if Windows
MenuDescription = $ ;Cause strings are too long to concatenate
[ MenuDescription, $
'1\Physics and Space Sciences', '', $
'0\Fourier Filtering', 'FILTER-SPACE', $
'2\ROI Segmentation', 'ROI-SPACE', $
'3\RSI Products', '', $
'0\IDL Insight', '.13', $
'0\ENVI', '.10', $
'0\Visible Human CD', '.11', $
'2\IDL Dataminer', '.12', $
'1\Features', '', $
'1\Visualization', '', $
'0\2D Plotting', 'D_PLOT2D', $
'0\Contouring', 'D_CONTOUR', $
'0\3D Geometry Viewing', 'D_OBJECT3D', $
'0\Surface Objects', 'D_SURFVIEW', $
'0\Volume Visualization', 'D_VOLRENDR', $
'0\Vibrating Membrane', 'D_VIBMEMBR', $
'0\Mapping', 'D_MAP', $
'0\Gridding and Interpolation', 'D_GRIDDING', $
'0\Texture Mapped Terrain', 'D_TEXTURE', $
'0\Terrain Flyby', 'D_FLYBY', $
'0\Orbiting Satellite', 'D_ORBIT', $
'2\Slicer', 'D_SLICE', $
'1\Data Analysis', '', $
'0\Math and Statistics', 'D_MATHSTAT', $
'0\Matrix Data', 'D_MATRIX', $
'0\Signal Processing', 'FILTER-SIGNAL', $
'0\Image Processing', 'D_IMAGPROC', $
'0\Venn Diagrams', 'D_VENN', $
'0\Wavelets', 'D_WAVELET', $
'2\The People of RSI', 'D_PEOPLE', $
'3\Application Development', '',$
'0\GUI Development', 'D_WIDGETS', $
'0\Database Connectivity', '.12', $
'0\Development Environment', '?DEVENV', $
'0\Object Oriented Programming', '?OOPROG', $
'2\Cross Platform Development', '?CROSS']
endelse
MenuDescription = $ ;Cause strings are too long to concatenate
[ MenuDescription, $
'1\Help', '', $
'2\IDL Online Help Navigator', '?NOARG', $
'1\About', '', $
'0\About the IDL Demo', '>abt_demo|About this Demo', $
'1\About Research Systems', '', $
'0\History of Research Systems', '>abt_rsi|History of Research Systems', $
'0\Distributors', ">abt_dist|Research Systems' Distributors", $
'0\The People of RSI', 'D_PEOPLE', $
'0\Training Courses', '>abt_trng|Research Systems Training', $
'0\Consulting', '>abt_cons|Research Systems Consulting', $
'0\IDL Information', '>abt_idl|IDL', $
'0\ENVI Information', '>abt_envi|ENVI', $
'2\Visible Human CD Information', '>abt_vh|Visible Human CD']
end ;getmenudescription
Function XFindFont, FontNames
; See if a font can be found. FontNames = an array of font names. On exit
; the function value is either the first found font, or the null string.
for i=0, n_elements(FontNames)-1 do begin ;Search for a font
Device, Font=FontNames(i), Get_Fontnum=fontnum, GET_FONTNAME=s
if fontnum gt 0 then return, s(0)
endfor
return, '' ;Couldn't find the font.
end
;----------------------------------------------------------------------------
;
; Purpose: Create the push down buttons.
;
pro createButtons, $
mainWinBase, $ ; IN: Main window base ID
buttons ; IN: buttons created bu buttonDef routine.
case !VERSION.OS_FAMILY of
'Windows' : button_font = 'MS Sans Serif*8'
'MacOS' : button_font = ''
ELSE: $ ; Find a font for Unix and VMS
button_font = XFindFont(['-adobe-helvetica-medium-r-normal--10-*-*-*', $
'-misc-fixed-medium-r-normal--10-*-*-*'])
ENDCASE
for i=0, N_ELEMENTS(buttons)-1 do begin
buttons[i].btnbase = WIDGET_BASE(mainWinBase, MAP=0, $
xoffset = buttons[i].xoffset, $
yoffset = buttons[i].yoffset)
buttonId = WIDGET_BUTTON(buttons[i].btnbase, $
VALUE=buttons[i].value, $
UVALUE=buttons[i].uvalue, $
XSIZE=buttons[i].xsize, $
YSIZE=buttons[i].ysize, $
FONT=button_font)
endfor
end
;----------------------------------------------------------------------------
;
; Purpose: read the required image index newScreen, and display it.
;
pro showScreen, newScreen, state
t0 = systime(1)
WSET, state.mainDrawID
Header = state.gif_hdr
Image = PReadDemoScreen(newScreen, header, colortb, DEBUG=state.debug)
state.gif_hdr = Header ;Restore gif status
WIDGET_CONTROL, state.imageBase, MAP=0 ;If we rearrange order of
; operations, this seems unnecessary.
TVLCT, colortb
TV, *image ;show it
for i=0, N_ELEMENTS(state.buttons)-1 do $ ;Map buttons for this screen
WIDGET_CONTROL, state.buttons[i].btnBase, $
MAP= state.buttons[i].screenNum eq newScreen
state.prevScreenNum = state.curScreenNum
state.curScreenNum = newScreen
WIDGET_CONTROL, state.imageBase, MAP=1
if state.debug then timer, 'ShowScreen ', t0
end
;----------------------------------------------------------------------------
;
; Purpose: Start the INSIGHT tool.
;
pro demoStartInsight, top
if (lmgr(/embedded) GT 0) then begin
result = DIALOG_MESSAGE(/QUESTION, $
DIALOG_PARENT=top, $
'Enter a time-limited IDL Insight session ?')
if (strupcase(result) EQ 'YES') then begin
tmp=lmgr(/force_demo)
insight
endif
endif else insight
end
;----------------------------------------------------------------------------
;
; Purpose: This routine is used to start the online
; help system. The user value (uval) can come
; from either a button or the pulldown menu
;
pro starthelp, $
uval, $ ; IN: user value
top ; IN: top level base
result = DIALOG_MESSAGE(/QUESTION, $
DIALOG_PARENT=top, $
['This choice will start the Online Help system.', $
'', $
'Do you want to continue ?'])
if (strupcase(result) EQ 'NO') then RETURN
case uval of
'DEVENV': begin
; Start the online help and display the page
; with the index for the IDL Development Environment
; for the applicable platform.
;
case !VERSION.OS_FAMILY of
'unix': online_help, 13010, /context
'vms': online_help, 13010, /context
'Windows': online_help, 14010, /context
'MacOS': online_help, 15010, /context
endcase
end
'OOPROG': online_help, book='oog'
; Start online help with the context number
; for "platforms supported".
;
'CROSS': online_help, 00010, /context
; Start the online help system with the default screen
;
'NOARG': online_help
endcase
end
;----------------------------------------------------------------------------
;
; Purpose: This routine is used to start all demos.
; Name must be the name of the procedure to call.
; a button or the pulldown menu
;
pro startapp, $
Name, $ ;Name of demo
state, $ ; IN: state structure
top, $ ; IN: top level base
EXTRA = extra ;Extra keyword parameter structure (optional)
if (WIDGET_INFO(state.apptlb, /VALID)) then begin
result = DIALOG_MESSAGE('Only one demo may run at a time')
RETURN
endif
if state.slow and (total(name eq state.slow_demos) gt 0) then begin
result = $
DIALOG_MESSAGE(['This demo utilizes computationally intensive', $
'graphics. Response on this machine may be', $
'unacceptably slow.', $
'Continue anyway?'], $
DIALOG_PARENT=top, $
/QUESTION)
;Only display once
state.slow_demos(where(state.slow_demos eq name)) = 'XXXX'
if result eq 'No' then return
endif
WIDGET_CONTROL, /HOURGLASS
idl_demo_reset
resolve_routine, Name ;Be sure its compiled/loaded
state.demo_name = Name ;Save name of demo
WIDGET_CONTROL, state.mainWinBase, map=0 ;Unmap menu
if state.debug then begin ;Clean up our memory first, we should
;have nothing allocated except the
;pointers for the screen cache.
ptr_free, state.gif_hdr.cache ;Free our screens
state.gif_hdr.cache = ptr_new() ;by clearing the cache...
state.memory = memory() ;Save memory state
endif
if n_elements(extra) gt 0 then $ ;Call it
call_procedure, Name, GROUP=top, APPTLB = appTLB, _EXTRA=extra $
else call_procedure, Name, GROUP=top, APPTLB = appTLB
if state.debug then begin
endif
if n_elements(appTLB) then state.appTlb = appTLB $
else state.appTlb = 0L
end
;----------------------------------------------------------------------------
;
; Purpose: GEt the screen size. Returns failure (0) if the
; screen size is too small, returns 1 (success)
; otherwise.
;
function IDL_DEMO_SIZE, $
DesiredX, $
DesiredY, $
ActualX, $
ActualY
DEVICE, GET_SCREEN_SIZE=scr_size
ActualX = scr_size[0]
ActualY = scr_size[1]
if ((DesiredX LE ActualX) AND (DesiredY LE ActualY)) then RETURN, 1
str_x = Strtrim(String(DesiredX), 2)
str_y = Strtrim(String(DesiredY), 2)
junk = DIALOG_MESSAGE(['The screen resolution must be at least', $
str_x + ' by ' + str_y + ' to run this demo.'])
RETURN, 0
end
;----------------------------------------------------------------------------
;
; Purpose: Initilize the main demo. Show the start up
; screen.
;
function DemoInit, $
fullScrXsize, $ ; IN: X monitor size
fullScrYsize ; IN: Y monitor size
case !Version.Os_Family OF
'vms': add = ''
'Windows': add = '\EXAMPLES\DEMO;'
'MacOS': add = ':Examples:Demo,'
ELSE: add = '/examples/demo:'
endcase
if add ne '' and strpos(!path, add) lt 0 then $ ;Add our path?
!Path = !Dir + add + !Path
if ((!D.Flags AND (2L^16)) NE (2L^16)) then begin
Print, ' '
Print, 'Unable to start the IDL demo.'
Print, 'The current device does not support widgets.'
Print, 'See the "SET_PLOT" command for more information.'
Print, ' '
RETURN, -1
endif
; Test for the presence of one of the demo save files to determine
; if the demos have been installed. (The main demo.sav file is
; always installed on some systems.) If the file is not present,
; exit with a warning.
openr, Lun, FILEPATH('d_animate.sav', SUBDIR=['examples','demo']), $
/GET_LUN, ERROR=i
if (i Lt 0) then begin
tmp = DIALOG_MESSAGE( /ERROR, [ $
'This IDL Demo application is missing files which are normally', $
'installed with the demo option of the installation.', $
'', $
'See your installation guide for details on installing the demo.'])
RETURN, -1
endif
Free_Lun, Lun
; Initialize the device.
;
if (((!D.Name EQ 'X') OR (!D.NAME EQ 'MacOS')) AND $
(!D.N_Colors GE 256L)) then DEVICE, Pseudo_Color=8
DEVICE, Decomposed=0, Bypass_Translation=0
; This is needed since the screens are unmapped and then mapped.
;
DEVICE, RETAIN=2
; Determine the Screen Size
;
if !Version.Os_Family EQ 'MacOS' then begin
minXsize = 640
minYsize = 440
endif else begin
minXsize = 640
minYsize = 480
endelse
if not(IDL_DEMO_SIZE(minXsize, minYsize, fullScrXsize, fullScrYsize)) $
then RETURN, -1
; Set default font for text in widgets
;
CASE !Version.OS_Family OF
; Don't set it for Windows or Mac, the systems defaults are fine
'Windows':
'MacOS':
ELSE: BEGIN ; Find a font for Unix and VMS.
save_wind = !D.Window
Window, /Free, Xsize=4, Ysize=4, /Pixmap, Retain=2
pix_win = !D.Window
Font = XFindFont(['-adobe-helvetica-medium-r-normal--14-*-*-*', $
'9x15'])
wdelete, pix_win
wset, save_wind
IF (font ne '') THEN Widget_Control, Default_Font= Font
ENDCASE
ENDCASE
RETURN, 1 ; Return 1 for success.
end
;----------------------------------------------------------------------------
;
; Purpose: Cleanup procedure.
;
pro idl_demo_cleanup, $
tlb ; IN: Top level base
WIDGET_CONTROL, tlb, GET_UVALUE=state, /NO_COPY
; Restore the previous color table.
;
TVLCT, state.colorTable
free_lun, state.gif_hdr.lun
ptr_free, state.gif_hdr.cache
!quiet = state.quiet
if state.debug then begin
print, "Looking for heap vars, windows, file units:
help, /heap
help, /files
print, '!d.window: ', !d.window
end
end ; idl_demo_cleanup
;----------------------------------------------------------------------------
;
; Purpose: Main event handler.
;
; The uvalue (or in the case of pulldown menus, the uvalue is saved in
; state.MenuActions) is encoded as follows:
; quit = quit
; INSIGHT-START = start insight.
; >FileName|Title = display the file FileName in the demotext
; directory, with the given title.
; .n = display screen n (n is a series of digits.)
; .- = display previous screen
; ?KEY = call STARTHELP with KEY
; NAME = call startapp with NAME
pro idl_demo_event, $
event ; IN: event structure.
; Quit the application using the close box.
;
WIDGET_CONTROL, event.top, GET_UVALUE=state, /NO_COPY, /HOURGLASS
if (TAG_NAMES(event, /STRUCTURE_NAME) EQ 'WIDGET_KILL_REQUEST') then begin
WIDGET_CONTROL, event.top, SET_UVALUE=state, /NO_COPY
WIDGET_CONTROL, event.top, /DESTROY
RETURN
endif
WIDGET_CONTROL,event.id,GET_UVALUE=uval
if state.debug and state.memory(0) ne 0L then begin ;Check demo's memory use?
mem_end = fix(memory()/1000L) ;In K...
mem_start = fix(state.memory/1000L)
print, 'Finished demo ', state.demo_name
print, 'Memory before start: ', mem_start(0), 'K, after: ', $
mem_end(0), ', delta: ', mem_end(0) - mem_start(0)
print, 'High-water mark: ', mem_start(4)
heap_gc, /VERBOSE
device, WINDOW_STATE=w ;Check for open windows
if total(w) gt 1 then begin ;Got too many windows open
print, 'ERROR: Only one window should be open:', where(w)
endif
state.memory = 0L
endif
; This CATCH branch handles unexpected errors that might
; arise in the event loop. Since the state is retrieved
; with NO_COPY, it is important to put it back into the
; user value of event.top so that execution can continue
; if there is an error caught by CATCH.
;
ErrorStatus = 0
CATCH, ErrorStatus
IF (ErrorStatus NE 0) THEN BEGIN
CATCH, /CANCEL
v = DIALOG_MESSAGE(['Unexpected error in DEMO:', $
'!ERR_STRING = ' + !ERR_STRING, $
'!SYSERROR = ' + STRTRIM(LONG(!SYSERROR), 2), $
'!SYSERR_STRING = ', !SYSERR_STRING, $
' ', 'Cleaning up...'], $
DIALOG_PARENT=event.top, $
/ERROR)
WIDGET_CONTROL, event.top, SET_UVALUE=state, /NO_COPY
WIDGET_CONTROL, event.top, /MAP
RETURN
ENDIF
; if state.debug then begin ;Debugging
; if total(tag_names(event) eq 'VALUE') ne 0 then v = event.value $
; else v = '<>'
; print, uval, ' ', v
; endif
if uval eq 'MAIN_PULLDOWN' then $ ;Translate menu pulldowns using action array
uval = state.MenuActions(event.value)
char = strmid(uval, 0, 1) ;What kind of action
rest = strmid(uval, 1, strlen(uval)-1)
if char eq '.' then begin ;Display a screen
if uval eq '.-' then showScreen, state.prevScreenNum, state $
else showScreen, fix(rest), state
endif else if char eq '>' then begin ;Display a file
parts = str_sep(rest, '|') ;Get file name & title
xdisplayfile, filepath(parts[0] + '.txt', $
SUBDIR=['examples','demo','demotext']), $
group=group, HEIGHT=35, WIDTH=80, $
title= parts[1]
endif else if char eq '?' then begin
starthelp, rest, event.top
endif else begin ;Must be a startapp
if uval eq 'quit' then begin ;Quit is a special case
WIDGET_CONTROL, event.top, SET_UVALUE=state ;Restore our state
WIDGET_CONTROL, event.top, /destroy
return
endif else if uval eq 'INSIGHT-START' then begin
demoStartInsight, event.top
endif else begin ;Just call the app
case uval of ;Check for special cases
'ROI-SPACE' : startapp, 'D_ROI', state, event.top, EXTRA={ASTRO:1}
'FILTER-SIGNAL' : startapp, 'D_FILTER', state, event.top, $
EXTRA={FILENAME: 'damp_sn.dat'}
'FILTER-ENGR': startapp, 'D_FILTER', state, event.top, $
EXTRA={FILENAME: 'damp_sn.dat'}
'FILTER-SPACE': startapp, 'D_FILTER', state, event.top, $
EXTRA={FILENAME:'galaxy.dat'}
else : startapp, uval, state, event.top ;Normal demo
endcase
endelse
endelse
WIDGET_CONTROL, event.top, SET_UVALUE=state, /NO_COPY ;Restore our state
END ; idl_demo_event
pro demo_timer, text, t0
t1 = systime(1)
print, text, ' ', t1 - t0
t0 = t1
end
;----------------------------------------------------------------------------
;
; Purpose: Main procedure for IDL 5.0 demo.
;
pro demo, $
debug=debug
; This is a list of demos that are slow. If we judge the machine to
; be slow, and we run one of these demos, a message is displayed the
; first time the demo is run.
if !version.os_family NE 'Windows' then begin
slow_demos = [ 'D_FLYBY', 'D_GLOBE', 'D_HEART', 'D_OBJECT3D', 'D_ORBIT', $
'D_SURFVIEW', 'D_TANKLEAK', 'D_TEXTURE', 'D_USCENSUS', $
'D_VIBMEMBR', 'D_VOLRENDR']
endif else begin
;;; Don't allow US Census demo if Windows
slow_demos = [ 'D_FLYBY', 'D_GLOBE', 'D_HEART', 'D_OBJECT3D', 'D_ORBIT', $
'D_SURFVIEW', 'D_TANKLEAK', 'D_TEXTURE', $
'D_VIBMEMBR', 'D_VOLRENDR']
endelse
debug = keyword_set(debug)
t0 = systime(1)
tstart = t0
quietsave = !quiet
!quiet = 1 ;Remove obnoxious messages
if ( xregistered ( "idl_demo" ) NE 0 ) then RETURN
if (demoInit(fullScrXsize, fullScrYsize) LT 0) then return
resolve_routine, 'd_animate' ;Cause it contains multiple files
if debug then timer, 'demoinit', t0
; Get the current color table.
; It will be restored when exiting.
;
TVLCT, colorTable, savedG, savedB, /GET
colorTable=[[colorTable],[savedG],[savedB]]
If OpenDemoScreens(filepath('screens.gif', $
SUBDIR=['examples','demo','demodata']), $
Header) $
lt 0 then return ;If we cant find screens file, adios.
; Read and display the splash screen
Image = PReadDemoScreen(n_elements(Header.start)-1, $ ;Index of splash screen
Header, Colortb, /NO_CACHE)
demoSplashStart, fullScrXsize, fullScrYsize, *Image, $ ; Display splash screen
colortb, splashBase, startSplash
Ptr_Free, Image ;No longer required
if debug then timer, 'demosplashstart', t0
WIDGET_CONTROL, /HOURGLASS
; Setup the Main Window and Pull Down Menus.
if ((!version.os_family EQ 'MacOS') AND $
(fullScrXsize LT 700 OR fullScrYsize LT 560)) then begin
; Use a scrolling base to allow access to all of demo screen on MacOS
; with small screen
xPad = 20
yPad = 20
mainWinBase = WIDGET_BASE ( TITLE="IDL Demo", /COLUMN, $
/ALIGN_CENTER, $
XSIZE=640, YSIZE=480, $
X_SCROLL_SIZE=fullScrXsize - xPad, $
Y_SCROLL_SIZE=fullScrYsize - yPad, $
MBAR=mainWinMenuBase, TLB_FRAME_ATTR=1, $
/TLB_KILL_REQUEST_EVENTS, $
MAP=0 )
endif else begin
mainWinBase = WIDGET_BASE ( TITLE="IDL Demo", /COLUMN, $
/ALIGN_CENTER, $
MBAR=mainWinMenuBase, TLB_FRAME_ATTR=1, $
/TLB_KILL_REQUEST_EVENTS, $
MAP=0 )
endelse
GetMenuDescription, MenuDescription
nmenus = n_elements(MenuDescription) /2 ;# of menu items.
MenuDescription = REFORM(MenuDescription, 2, nmenus, /OVERWRITE)
mainWinMenu = CW_PDMENU ( mainWinMenuBase, MenuDescription(0,*), $
/RETURN_INDEX, /MBAR, UVALUE='MAIN_PULLDOWN' )
; Create the base for the images and buttons.
imageBase = WIDGET_BASE(mainWinBase, XSIZE=630, YSIZE=410)
; Create the status message area.
startMainStatus = "Welcome to the IDL 5.0 Demo: Please select a topic..."
currMainStatus = startMainStatus
statusAreaBase = WIDGET_BASE ( mainWinBase, frame=3 )
statusAreaMsg = WIDGET_LABEL(statusAreaBase, VALUE=startMainStatus, $
/ALIGN_LEFT )
if debug then timer, 'MainWindowCreate', t0
; Do as much as possible to load the main image before ending splash screen.
buttonDef, buttons
if debug then timer, 'ButtonDef', t0
createButtons, imageBase, buttons
if debug then timer, 'CreateButtons', t0
newMainDraw = WIDGET_DRAW(imageBase, XSIZE=630, YSIZE=410)
WIDGET_CONTROL, mainWinBase, /REALIZE, MAP=0
WIDGET_CONTROL, newMainDraw, GET_VALUE=mainDrawID
WSET, mainDrawID
; Take down the splash screen.
;
demoSplashEnd, startSplash, splashBase, debug
if debug then timer, 'SplashEnd', t0
mainWinInfo = { $ ; Create the main state structure.
mainWinBase:mainWinBase, $
imageBase : imageBase, $
buttons: buttons, $
mainDrawID: mainDrawID, $
apptlb : 0L, $
curScreenNum: 0L, $
prevScreenNum: 0L, $
MenuActions : MenuDescription(1,*), $
colorTable: colorTable, $ ; Color table to restore
quiet: quietsave, $
gif_hdr: temporary(header), $
slow : 0, $
demo_name: '<Startup>', $
memory : memory(), $
debug : debug, $
slow_demos : slow_demos $
}
MenuDescription = 0 ;All done with the menu
showScreen, 0, mainWinInfo
WIDGET_CONTROL, mainWinBase, /map
;Is this machine slow? Very approximate...
mainWinInfo.slow = (systime(1) - tstart ) gt 5
; Save state in top base uvalue
WIDGET_CONTROL, mainWinBase, SET_UVALUE=mainWinInfo, /no_copy
; Register program with XManager.
;
if debug then timer, 'Total Time', tstart
XMANAGER, "idl_demo", mainWinBase, $
EVENT_HANDLER="idl_demo_event", $
/NO_BLOCK, $
CLEANUP="idl_demo_cleanup"
end ; idl_demo
; * Main Procedure for embedded mode.
PRO MAIN
DEMO
END